/**
 * FileName: ProductPropertyServiceImpl
 * Author: Wb
 * Date: 2025/9/26 18:11
 * Description:
 * History:
 */
package org.test.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.test.device.constant.AttributesValue;
import org.test.device.enty.ProductProperty;
import org.test.device.mapper.ProductPropertyMapper;
import org.test.device.params.QueryProductPropertyParam;
import org.test.device.service.ProductPropertyService;
import org.test.device.utils.SqlTypeConverter;
import org.test.device.vo.product.ProductPropertyVoList;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author Wb
 * @create 2025/9/26
 * @since 1.0.0
 */
@Slf4j
@Service
public class ProductPropertyServiceImpl implements ProductPropertyService {

    @Autowired
    ProductPropertyMapper productPropertyMapper;

    @Override
    public List<ProductPropertyVoList> getProductPropertyList(QueryProductPropertyParam param) {
        //获取物模型列表信息
        LambdaQueryWrapper<ProductProperty> ppWrapper = new LambdaQueryWrapper<>();
        ppWrapper.eq(ProductProperty::getDeleted, AttributesValue.NOT_DELETED.getCode());
        Optional.ofNullable(param.getDeviceId())
                .filter(Objects::nonNull)
                .ifPresent(d -> ppWrapper.eq(ProductProperty::getDeviceId, d));

        Optional.ofNullable(param.getProductId())
                .filter(Objects::nonNull)
                .ifPresent(p->ppWrapper.eq(ProductProperty::getProductId,p));
        List<ProductProperty> propertyList = productPropertyMapper.selectList(ppWrapper);
        return propertyList.stream()
                .map(property -> {
                    ProductPropertyVoList ppVo = new ProductPropertyVoList();
                    // 利用转换器复制字段（假设工具类支持）
                    SqlTypeConverter.convertEntity(property, ppVo, "yyyy-MM-dd HH:mm:ss");
                    return ppVo;
                })
                .collect(Collectors.toList());
    }
}